package com.dinadi.yidi.ui.view;


import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.dinadi.yidi.R;


/**
 * 自定义dialog
 * 工具类
 */
public class CommonDialogUtils2 {
    Context context;
    Dialogcallback dialogcallback;
    Dialogcallback2 dialogcallback2;
    Dialog dialog;
    TextView cancel, determine;
    TextView tishi1, tishi2;


    public CommonDialogUtils2(Context con) {
        this.context = con;
//		dialog = new Dialog(context, R.style.dialog);
        dialog = new Dialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dialog_common);
        dialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        tishi1 = (TextView) dialog.findViewById(R.id.tishi1);
        tishi2 = (TextView) dialog.findViewById(R.id.tishi2);
        cancel = (TextView) dialog.findViewById(R.id.cancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                dialogcallback2.dialogdo2();

            }
        });
        determine = (TextView) dialog.findViewById(R.id.determine);
        determine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogcallback.dialogdo();

            }
        });
    }

    /**
     * 设定一个interfack接口,使mydialog可以处理activity定义的事
     */
    public interface Dialogcallback {
        void dialogdo();
    }

    public void setDialogCallback(Dialogcallback dialogcallback) {
        this.dialogcallback = dialogcallback;
    }


    public interface Dialogcallback2 {
        void dialogdo2();
    }

    public void setDialogCallback2(Dialogcallback2 dialogcallback2) {
        this.dialogcallback2 = dialogcallback2;
    }

    /**
     * 设置提示的内容
     */
    public void setTitle(int content) {
        tishi1.setText(content);
    }

    public void setContent(int content) {
        tishi2.setText(content);
    }

    public void setContent(CharSequence content) {
        tishi2.setText(content);
    }

    public void determineText(int content) {
        determine.setText(content);
    }

    public void isShow(boolean isShow) {
        tishi1.setVisibility(isShow ? View.VISIBLE : View.GONE);
    }

    public void show() {
        dialog.show();
    }

    public void hide() {
        dialog.hide();
    }

    public void dismiss() {
        dialog.dismiss();
    }
}
